<template>

	<a-upload
		v-model:file-list="fileList"
		list-type="picture"
		:before-upload="beforeUpload" @remove="handleRemove"
		:preview-file="previewFile"
		@change="changeHandler"
		:max-count="1"
	>
		<a-button>
			<upload-outlined></upload-outlined>
			上传
		</a-button>
	</a-upload>

</template>
<script setup  >
import { ref } from 'vue';
const emit = defineEmits({successful: null})
const open = ref(false)
const handleRemove = file => {
	const index = fileList.value.indexOf(file);
	const newFileList = fileList.value.slice();
	newFileList.splice(index, 1);
	fileList.value = newFileList;
};
const beforeUpload = file => {
	fileList.value = [...(fileList.value || []), file];
	return false;
};

const previewFile = async file => {

	return "https://03235615.oss-cn-beijing.aliyuncs.com/8Qetm6G7CFEefdhYd5.mp4";
};
const fileList = ref([ {
	uid: '1',
	name: 'xxx.png',
	status: 'done',
	response: 'Server Error 500',
	// custom error message to show
	url: 'http://www.baidu.com/xxx.png',
},]);


const changeHandler = (e) => {
	console.log(fileList.value)

	var uploader = new AliyunUpload.Vod({
		// userID，用于标识上传者的身份，必填，有值即可，可以是阿里云账号ID或者您自定义的用户ID，您可以访问阿里云账号中心（https://account.console.aliyun.com/）查看账号ID
		userId: "122",
		// 上传到视频点播的地域，默认值为'cn-shanghai'，
		//eu-central-1，ap-southeast-1
		region: "cn-beijing",
		// 分片大小默认1 MB，不能小于100 KB（100*1024）
		partSize: 1048576,
		// 并行上传分片个数，默认5
		parallel: 5,
		// 网络原因失败时，重新上传次数，默认为3
		retryCount: 3,
		// 网络原因失败时，重新上传间隔时间，默认为2秒
		retryDuration: 2,

		// 开始上传
		onUploadstarted: function (uploadInfo) {
			uploader.setSTSToken(uploadInfo,
				"STS.NYG8hkPcaB4UyjgZAMS1smZ1A",
				"9C4s4YzwCjTCUChApMA9yEnjnpsp3zcFsQygiJD8sC7U",
				"CAISxgJ1q6Ft5B2yfSjIr5ryc9LfvbxA9fa+e0zWvkEYX75fgp+aozz2IHhMeHdrBukatPUxn29S7/0blqVoRoReREvCKM1565kPfa07sRyb6aKP9rUhpMCPPwr6UmzavqL7Z+H+U6mqGJOEYEzFkSle2KbzcS7YMXWuLZyOj+wIDLkJWQXqL0AxZrFsKxBltdUROFbIKP+pKWSKuGfLC1dysQcO4gEWq4bHm5LMsEWF1QWnlLZJ+d2ufqLJNZc8YM1NNP6ux/Fze6b71ypd1gNH7q8ejtYfoW+b4IrCWgULskvdbLCNqYR1SAJ1e+0kHKIBtv/4mO3uH1dhWUAKoPwkHZa2M0y3LOjIqKNPCHmzhHAuW5zPmmUf8xF+B2jkMjleFVYxHi0kVZRP1FE+95KCxD8kxIdrUJhmyKrr5yAttMl+MhC5kj2AlRqAAXwYqgRI3E872sUOpqnUoBzaPDx4Fx2WQYEwTlUKJ2NoSNmrBDKs63wFQlIIhmPBQUQeT8ev6T/lMD9A1/7fXSxpbfNygRTT+suGR/1cuLpPeEFG2a/H3hFb1JmtUIxmgMaXu4PvQatptz9Qw31SgfTAi9gou8DuLtCHwAaMW8+fIAA=");
		},
		// 文件上传成功
		onUploadSucceed: function (uploadInfo) {
			console.log("文件上传成功", uploadInfo)
			fileList.value[0].url = "https://edu-vod.hongwell.xyz/"+uploadInfo.object
			emit(
				'successful',
				uploadInfo
			)
		},
		// 文件上传失败
		onUploadFailed: function (uploadInfo, code, message) {
			console.log("文件上传失败", uploadInfo, code, message)

		},
		// 文件上传进度，单位：字节
		onUploadProgress: function (uploadInfo, totalSize, loadedPercent) {
			console.log("文件上传进度，单位：字节", uploadInfo, totalSize, loadedPercent)

		},
		// 上传凭证或STS token超时
		onUploadTokenExpired: function (uploadInfo) {
			// uploader.resumeUploadWithSTSToken(info.AccessKeyId, info.AccessKeySecret, info.SecretToken);
		},
		// 全部文件上传结束
		onUploadEnd: function (uploadInfo) {
		},
	});
	const paramData = {
		Vod: {
			FileName: "vue大大大奔驰.mp4",
			Title: "vue大大大奔驰 ** ** **",
			UserData: {
				/* MessageCallback: {
				   CallbackType: "http",
				   CallbackURL: "http://r533886b.natappfree.cc/vod/callback"
				 },*/
				Extend:"hello world"
			}
		}
	}
	uploader.addFile(fileList.value[0].originFileObj, null, null, null, JSON.stringify(paramData))
	uploader.startUpload();
}


</script>

<style scoped lang="less"></style>
